package actions;

import java.util.Date;
import java.util.Map;

import mail.Mail;

import DBMailDAO.DBMailDAO;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class SetSelectedReadAction extends ActionSupport{
	public String setSelectedRead(){
		long selectedId;
		
		DBMailDAO dbmail = new DBMailDAO();
		Map<String, Object> params = ActionContext.getContext().getParameters();
		Object param;
		param = params.get("selectedIds");
		String[] strParam = (String[]) param;		
		String[] strSelectedIds = strParam[0].split(",");
		for (int i = 0; i < strSelectedIds.length; i++) {
			selectedId = Long.parseLong(strSelectedIds[i]);
			Mail mail = dbmail.loadMailById(selectedId);
			if(mail.getReceiveTime() == null){
				Date receiveTime = new Date();
				dbmail.setReadTime(mail, receiveTime);
			}
			dbmail.setMailRead(mail);
		}
		
		
		return SUCCESS;
	}

}
